const path = require('path')
const madkdown = require('./build/md-loader/index.js')
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('md')
      .test(/\.md/)
      .use('vue-loader')
      .loader('vue-loader')
      .end()
      .use('vue-markdown-loader')
      .loader('vue-markdown-loader/lib/markdown-compiler')
      .options({
        raw: true,
        use: madkdown.markdownContainer(),
        // preprocess：定义处理规则
        preprocess: (MarkdownIt, source) => {
          MarkdownIt.renderer.rules.table_open = function () {
            return '<table class="table">'
          }
          MarkdownIt.renderer.rules.fence = madkdown.wrapCustomClass(MarkdownIt.renderer.rules.fence)
          // ```code`` 给这种样式加个class code_inline
          const codeInline = MarkdownIt.renderer.rules.code_inline
          MarkdownIt.renderer.rules.code_inline = function (...args) {
            args[0][args[1]].attrJoin('class', 'code_inline')
            return codeInline(...args)
          }
          return source
        }
      })
  }
}
